/**************************新书分发模板*************************************************/
//选择客户的按钮
function chooseClientMB(obj){
	_data_qw('mff','ds_client_for_ffmb','fft_sure1','44','',''); 
}


//弹窗中的确定按钮
function _fft_sure(){
	$('#mff_DATA_PARENT_PANEL').window('close');
	var selRows = $('#mff_DATA_DATALIST').datagrid('getSelections');
	var allRows = $('#fft_addItemDatagrid').datagrid('getRows');
	var length=allRows.length;
	var jhs = 0;
	var clId = '';
	var address = "";
	if(length==0){
		for ( var i = 0; i < selRows.length; i++) {
			if(selRows[i].RATIO == '' || selRows[i].RATIO == null){
				selRows[i].RATIO = 0;
			}
			$('#fft_addItemDatagrid').datagrid('appendRow', {
				CLIENT_ID:selRows[i].CLIENTS_ID,
//				RATIO:selRows[i].RATIO,
				CC_ID: selRows[i].CC_ID,
				PROVINCE_ID:selRows[i].PROVINCE_ID,
				O_ID_LASTGR:selRows[i].O_ID_LASTGR
			}); 
		}
	}else{
		for ( var j = 0; j < selRows.length; j++) {
			currRow=selRows[j];
			if(currRow.RATIO == '' || currRow.RATIO == null){
				currRow.RATIO = 0;
			}
			for(var i=0;i<allRows.length;i++){
				if(currRow.CLIENTS_ID==allRows[i].CLIENT_ID){
					break;
				}else{
					if(i==(allRows.length-1)){
						$('#fft_addItemDatagrid').datagrid('appendRow', {
							CLIENT_ID:selRows[j].CLIENTS_ID,
//							RATIO:selRows[j].RATIO,
							CC_ID: selRows[j].CC_ID,
							PROVINCE_ID:selRows[j].PROVINCE_ID,
							O_ID_LASTGR:selRows[j].O_ID_LASTGR
						});
					}
				}
			}
		}
		
	}
}



/**
 * 导入客户
 * @param dsId
 * @param flag
 * @param hdFunc
 * @param tdsId
 * @param thdFunc
 * @return
 */
function loadDataExcKH(dsId,flag,tdsId){
	if($('#IMP_EXC_WIN').length>0){
		$('#IMP_EXC_PARENT_PANEL').window('close');
		var obj = document.getElementById("IMP_EXC_WIN");
		$('#IMP_EXC_PARENT_PANEL').remove();
		document.body.removeChild(obj);
	}
	var div_box = document.createElement("DIV");
	div_box.id = "IMP_EXC_WIN";
	div_box.height = 100;
	document.body.appendChild(div_box);
	
	$("#IMP_EXC_WIN").attr("tdsId",tdsId); //第二个弹窗中的加载列的DSID
	 
	$('#IMP_EXC_WIN').load(_m_url+'model/improeExcelInfo/imprortExcelKH.jsp',//加载客户jsp
	function(){
		$.parser.parse('#IMP_EXC_DG_PANEL');
		$('#IMP_EXC_PARENT_PANEL').window({  
			width:document.documentElement.clientWidth,  
			height:document.documentElement.clientHeight,  
			draggable:false,
			top: 0,
			left: 0,
			modal:true,
			resizable:false,
			closable:false,
			collapsible:false,
			maximizable:false,
			minimizable:false
		}); 
		 $("#importexcel").attr("dsid",dsId);
		 $("#download").attr("href","/publishUI/singlePages/dow?fileName="+flag+".xlsx");
		 //给确认按钮写事件
	    $("#affirmbtn").attr("onclick","saveMateSuccessInfo('"+flag+"')");  
		$.ajax({
			type:'post',
			url:_m_url+'framework/loadColumnsU',
			data:{'colId':dsId,'type':4},
			success:function(data){
				$('#IMP_EXC_DATALIST').datagrid({
					iconCls:'icon-save',
					height:document.documentElement.clientHeight-125 ,
					width:document.documentElement.clientWidth - 20,
					minHeight:450,
					minWidth:1180,
					striped: true,		
					collapsible:true,
					autoRowHeight: false,		
					sortOrder: 'desc',
					remoteSort: false,
					fixed:true,
					columns:jointDGColumn(data[0]).columns,
			        rowStyler: function(index,row){
						if (row.IS_PP==0){
							return 'background-color:#bbddf5;';
						}
					},
					singleSelect:true,
					onSelect:function(rowIndex,rowData){
						
					},
					//双击执行效果
					onDblClickRow: function(index,field,value){
						var selected = $("#IMP_EXC_DATALIST").datagrid("getSelected");
						if(selected.IS_PP.trim()=="0"){
						  	var div_box = document.createElement("DIV");
						  	div_box.id = "IMP_MATA_WIN";
						  	div_box.height = 100;
						  	document.body.appendChild(div_box);
						  	var cName=selected.C_NAME;
						  	$.ajax({
						  		url: _m_url+"singlePages/mataOrderKH",
								data:{'cname':cName},
								success: function(data){
								  $("#IMP_MATA_DATALIST").datagrid('loadData', data); 
								  $('#manage_ap').window("open");
								}
							});
						}
					}
				}); 
			}
		});
	});				
}